package com.cheyunkeji.er.activity.fast_evaluate;

import android.os.Build;
import android.text.Html;
import android.text.TextUtils;
import android.util.Log;
import android.widget.TextView;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.Constants;
import com.cheyun.netsalev3.MyApplication;
import com.cheyunkeji.er.base.BaseActivity;
import com.cheyunkeji.er.bean.fast_evaluate.NoticeDetail;
import com.cheyunkeji.er.http.ApiClient;
import com.cheyunkeji.er.http.HttpConstants;
import com.cheyunkeji.er.http.RespCallback;
import com.cheyunkeji.er.view.SToast;
import com.cheyunkeji.er.view.TopBar;

import java.util.HashMap;

import butterknife.BindView;
import butterknife.ButterKnife;
import okhttp3.Request;

public class NoticeDetailActivity extends BaseActivity {

  @BindView(R.id.notice_detail_topbar)
  TopBar noticeDetailTopbar;

  @BindView(R.id.notice_detail_content)
  TextView noticeDetailContent;

  @Override
  protected void init() {
    setContentView(R.layout.er_activity_notice_detail);
    ButterKnife.bind(this);
  }

  @Override
  protected void initView() {
    noticeDetailTopbar.setTitle("公告详情");
    noticeDetailTopbar.setLeftBack();

    //        根据当前模块选择
    if (MyApplication.getInstance().getCurrentModuleType()
        == Constants.CURRENT_MODULE_TYPE_FAST_EVALUATE) {
      noticeDetailTopbar.setBackgroundColor(getResources().getColor(R.color.bkg_blue));
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getWindow().setStatusBarColor(getResources().getColor(R.color.bkg_blue));
    } else if (MyApplication.getInstance().getCurrentModuleType()
        == Constants.CURRENT_MODULE_TYPE_FULL_EVALUATE) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getWindow().setStatusBarColor(getResources().getColor(R.color.auction_status_bar));
      noticeDetailTopbar.setBackgroundColor(getResources().getColor(R.color.auction_status_bar));
    } else if (MyApplication.getInstance().getCurrentModuleType()
        == Constants.CURRENT_MODULE_TYPE_AUCTION) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        getWindow().setStatusBarColor(getResources().getColor(R.color.auction_status_bar));
      noticeDetailTopbar.setBackgroundColor(getResources().getColor(R.color.auction_status_bar));
    }
  }

  @Override
  protected void initData() {

    if (!TextUtils.isEmpty(getIntent().getStringExtra("nid")))
      loadRecordListData(getIntent().getStringExtra("nid"));
  }

  private void loadRecordListData(String nid) {

    HashMap<String, String> params = new HashMap<>();
    //      params.put("authkey",
    // UserInfoManager.getInstance(MyApplication.getInstance()).getAuthKey());//
    // params.put(ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getYkey(),
    // ChannelInfoUtil.getCurrentChannelInfo().getCkey1().getY7e_e73a691f02a46500201c3998e6a2989d());
    params.put("nid", nid);

    ApiClient.postForm(
        HttpConstants.EVALUATE_NOMAIL_INFO,
        params,
        new RespCallback<NoticeDetail>() {

          @Override
          protected void onRequestFailed(String msg) {
            SToast.show(msg);
          }

          @Override
          protected void onSuccess(final NoticeDetail data) {

            Log.e("===", data.toString());
            noticeDetailContent.setText(Html.fromHtml(data.getContent()));
          }

          @Override
          public void onBefore(Request request, int id) {
            showDialog();
          }

          @Override
          public void onAfter(int id) {
            dismissDialog();
          }
        });
  }
}
